﻿namespace Microsoft.VisualStudio.IDE.ToolboxControlsInstaller
{
    using Microsoft.Windows.Design.Interaction;
    using Microsoft.Windows.Design.Metadata;
    using Microsoft.Windows.Design.Metadata.Reflection;
    using System;

    public class CreationToolCreator
    {
        internal static CreationTool GetCreationTool(IMetadataContext metadata, Type controlType)
        {
            ITypeMetadata type = metadata.GetType(typeof(CreationToolAttribute));
            ITypeMetadata metadata3 = metadata.GetType(controlType);
            CreationTool tool = null;
            foreach (IAttributeMetadata metadata4 in metadata3.GetAttributes(type))
            {
                CreationToolAttribute attribute = (CreationToolAttribute) metadata4.GetValue();
                if (attribute.get_ToolType() != null)
                {
                    tool = Activator.CreateInstance(attribute.get_ToolType()) as CreationTool;
                }
                if (tool != null)
                {
                    tool.set_CreationType(controlType);
                }
                return tool;
            }
            return tool;
        }
    }
}

